<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productSpuId" label="商品SPU ID">
          <a-input placeholder="请输入商品SPU ID" v-model="model.productSpuId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemCode" label="商品编码">
          <a-input placeholder="请输入商品编码" v-model="model.itemCode" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemName" label="商品名称">
          <a-input placeholder="请输入商品名称" v-model="model.itemName" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemShortName" label="商品简称">
          <a-input placeholder="请输入商品简称" v-model="model.itemShortName" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemSku" label="源单商品SKU">
          <a-input placeholder="请输入源单商品SKU" v-model="model.itemSku" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemSession" label="源单商品季节">
          <a-input placeholder="请输入源单商品季节" v-model="model.itemSession" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemType" label="源单商品类型（砍货|正价）">
          <a-input placeholder="请输入源单商品类型（砍货|正价）" v-model="model.itemType" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemColor" label="颜色">
          <a-input placeholder="请输入颜色" v-model="model.itemColor" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemSize" label="尺码">
          <a-input placeholder="请输入尺码" v-model="model.itemSize" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brandName" label="品牌名">
          <a-input placeholder="请输入品牌名" v-model="model.brandName" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemCate" label="分类">
          <a-input placeholder="请输入分类" v-model="model.itemCate" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemCateName" label="分类名称">
          <a-input placeholder="请输入分类名称" v-model="model.itemCateName" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyId" label="供应商id">
          <a-input placeholder="请输入供应商id" v-model="model.supplyId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyNo" label="供应商编码">
          <a-input placeholder="请输入供应商编码" v-model="model.supplyNo" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyName" label="供应商名称">
          <a-input placeholder="请输入供应商名称" v-model="model.supplyName" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyPrice" label="供应价（分）">
          <a-input-number v-model="model.supplyPrice"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="markPrice" label="市场参考价（分）">
          <a-input-number v-model="model.markPrice"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit" label="单位">
          <a-input placeholder="请输入单位" v-model="model.unit" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="photo" label="封面图url">
          <a-input placeholder="请输入封面图url" v-model="model.photo" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pics" label="多图">
          <a-input placeholder="请输入多图" v-model="model.pics" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pStatus" label="上架状态">
          <a-input placeholder="请输入上架状态" v-model="model.pStatus" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="freightRuleId" label="运费规则id">
          <a-input placeholder="请输入运费规则id" v-model="model.freightRuleId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="freight" label="运费">
          <a-input-number v-model="model.freight"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus" label="状态：1为审核 0为未审核">
          <a-input placeholder="请输入状态：1为审核 0为未审核" v-model="model.auditStatus" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enableAreaType" label="可售地区限制类型 0为不限制 1只有某省份可售 2只有某市可售 3只有某区可售 4 为模板限售">
          <a-input placeholder="请输入可售地区限制类型 0为不限制 1只有某省份可售 2只有某市可售 3只有某区可售 4 为模板限售" v-model="model.enableAreaType" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateId" label="限售模板id">
          <a-input placeholder="请输入限售模板id" v-model="model.templateId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="province" label="可售省">
          <a-input placeholder="请输入可售省" v-model="model.province" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="city" label="可售市">
          <a-input placeholder="请输入可售市" v-model="model.city" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="country" label="可售区县">
          <a-input placeholder="请输入可售区县" v-model="model.country" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="refundStatus" label="退换货类型 1为支持退换货 0为不支持">
          <a-input placeholder="请输入退换货类型 1为支持退换货 0为不支持" v-model="model.refundStatus" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nappintroduction" label="移动端详情">
          <a-input placeholder="请输入移动端详情" v-model="model.nappintroduction" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content" label="PC详情">
          <a-input placeholder="请输入PC详情" v-model="model.content" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="source" label="来源 1:ERP 2:自有 3:平台">
          <a-input placeholder="请输入来源 1:ERP 2:自有 3:平台" v-model="model.source" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditTimes" label="审核次数">
          <a-input placeholder="请输入审核次数" v-model="model.auditTimes" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tax" label="税率">
          <a-input-number v-model="model.tax"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxPrice" label="税额">
          <a-input-number v-model="model.taxPrice"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sort" label="排序字段">
          <a-input-number v-model="model.sort"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recommendFlag" label="推荐标识 1：推荐 0：非推荐">
          <a-input placeholder="请输入推荐标识 1：推荐 0：非推荐" v-model="model.recommendFlag" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="upcCode" label="upc69条码">
          <a-input placeholder="请输入upc69条码" v-model="model.upcCode" />
        </a-form-model-item>
		
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import moment from "moment"

  export default {
    name: "SupplyProductModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        productSpuId:[{ required: true, message: '请输入商品SPU ID!' }],
        itemCode:[{ required: true, message: '请输入商品编码!' }],
        itemName:[{ required: true, message: '请输入商品名称!' }],
        itemSku:[{ required: true, message: '请输入源单商品SKU!' }],
        },
        url: {
          add: "/stock.supply/supplyProduct/add",
          edit: "/stock.supply/supplyProduct/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        //初始化默认值
        this.edit({});
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>